<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity5">
<head>
    <meta charset="UTF-8">
    <title>订单管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta http-equiv="Access-Control-Allow-Origin" content="*">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <link rel="icon" th:href="@{/favicon.ico}">
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/css/public.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/layui_ext/dtree/dtree.css}" media="all"/>
    <link rel="stylesheet" th:href="@{/layui_ext/dtree/font/dtreefont.css}" media="all"/>
    <style>
        .layui-elem-quote .layui-form .layui-form-item .layui-input-inline {
            width: 150px;
        }
    </style>
</head>
<body class="childrenBody" sec:authorize="hasPermission('/admin/order/toOrder',null)">
<!-- 查询条件开始 -->
<blockquote class="layui-elem-quote">
    <form action="" method="post" id="searchFrm" lay-filter="searchFrm" class="layui-form layui-form-pane">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 90px">所属城市</label>
                <div class="layui-input-inline">
                    <select name="cId" id="search_city" lay-search="">
                        <option value="">请选择城市</option>
                    </select>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 150px">经纪人/卖家(房东)</label>
                <div class="layui-input-inline">
                    <input type="text" name="aName" autocomplete="off" class="layui-input"  style="width: 150px">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">买家</label>
                <div class="layui-input-inline">
                    <input type="text" name="oBuyer" autocomplete="off" class="layui-input"  style="width: 150px">
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 80px">订单号</label>
                <div class="layui-input-inline">
                    <input type="text" name="id" autocomplete="off" class="layui-input" style="width: 300px">
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="radio" name="status" value="" title="全部" checked="">
                    <input type="radio" name="status" value="1" title="未付款">
                    <input type="radio" name="status" value="2" title="已付款" >
                    <input type="radio" name="status" value="3" title="已取消" >
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">类型</label>
                <div class="layui-input-block">
                    <input type="radio" name="type" value="" title="全部" checked="">
                    <input type="radio" name="type" value="1" title="新房">
                    <input type="radio" name="type" value="2" title="二手房" >
                    <input type="radio" name="type" value="3" title="租房" >
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block" style="text-align: center;">
                <button type="button" class="layui-btn layui-btn-sm" lay-submit="" lay-filter="doSearch">
                    <span class="layui-icon layui-icon-search"></span>查询
                </button>
                <button type="reset" class="layui-btn layui-btn-warm layui-btn-sm"><span class="layui-icon layui-icon-refresh-1"></span>重置
                </button>
            </div>
        </div>
    </form>
</blockquote>
<!-- 查询条件结束-->


<!-- 数据表格开始 -->
<div>
    <table class="layui-hide" id="orderTable" lay-filter="orderTable"></table>

    <div id="orderRowBar" style="display: none;">
        {{#  if(d.type == 1 || d.type == 2 ){ }}
        <button type="button" lay-event="look1" class="layui-btn layui-btn-sm"><span
                class="layui-icon layui-icon-search"></span>查看详情
        </button>
        {{#  } }}
        {{#  if(d.type == 3){ }}
        <button type="button" lay-event="look2" class="layui-btn layui-btn-sm"><span
                class="layui-icon layui-icon-search"></span>查看详情
        </button>
        {{#  } }}
        {{#  if(d.status == 1){ }}
        <button type="button" lay-event="delete" class="layui-btn layui-btn-sm layui-btn-danger" sec:authorize="hasPermission('/admin/order/cancelOrder','order:cancel')">
            <span class="layui-icon layui-icon-delete"></span>取消
        </button>
        {{#  } }}
    </div>
</div>

<!-- 数据表格结束 -->

<!-- 查看房屋的弹出层开始 -->
<div style="display: none;padding: 5px" id="lookDiv1">
    <form action="" method="post" class="layui-form layui-form-pane" id="dataFrm1" lay-filter="dataFrm">
        <input hidden name="id" value="id">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" id="title" class="layui-input" style="width: 400px" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">城市</label>
                <div class="layui-input-inline">
                    <input type="text" name="cName" id="cName" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">楼盘小区</label>
                <div class="layui-input-inline">
                    <input type="text" name="quarters" id="quarters" class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-inline">
                    <input type="text" name="local" id="local" class="layui-input"  style="width: 600px" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">出售类型</label>
                <div class="layui-input-inline">
                    <input type="text" name="type" id="type" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">装修风格</label>
                <div class="layui-input-inline">
                    <input type="text" name="dName" id="dName" class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">房屋特色</label>
                <div class="layui-input-inline">
                    <input type="text" name="characteristic" id="characteristic"  class="layui-input" style="width: 600px" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 110px">价格(万元)</label>
                <div class="layui-input-inline">
                    <input type="number" name="price" id="price" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 110px">面积(m³)</label>
                <div class="layui-input-inline">
                    <input type="number" name="area" id="area1" class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">楼层</label>
                <div class="layui-input-inline">
                    <input type="number" name="higth" id="higth" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">总层数</label>
                <div class="layui-input-inline">
                    <input type="number" name="allhigth" id="allhigth" class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">经纪人</label>
                <div class="layui-input-inline">
                    <input type="text" name="aName" id="aName" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-inline">
                    <input type="number" name="aphone" id="aphone" class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">卖家</label>
                <div class="layui-input-inline">
                    <input type="text" name="saName" id="saName" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-inline">
                    <input type="number" name="saphone" id="saphone" class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">详细描述</label>
            <div class="layui-input-block">
                <textarea name="details" id="details" class="layui-textarea" disabled></textarea>
            </div>
        </div>
    </form>
</div>
<!-- 查看房屋的弹出层结束 -->

<!-- 查看房屋的弹出层开始 -->
<div style="display: none;padding: 5px" id="lookDiv2">
    <form action="" method="post" class="layui-form layui-form-pane" id="dataFrm2" lay-filter="dataFrm">
        <input hidden name="id" value="id">
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-inline">
                    <input type="text" name="title" id="title2" class="layui-input" style="width: 400px" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">城市</label>
                <div class="layui-input-inline">
                    <input type="text" name="cName" id="cName2" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">楼盘小区</label>
                <div class="layui-input-inline">
                    <input type="text" name="quarters" id="quarters2" class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">地址</label>
                <div class="layui-input-inline">
                    <input type="text" name="local" id="local2" class="layui-input"  style="width: 600px" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">房屋特色</label>
                <div class="layui-input-inline">
                    <input type="text" name="characteristic" id="characteristic2"  class="layui-input" style="width: 600px" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 110px">价格(元/月)</label>
                <div class="layui-input-inline">
                    <input type="number" name="price" id="price2" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label" style="width: 110px">面积(m³)</label>
                <div class="layui-input-inline">
                    <input type="number" name="area" id="area2" class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">楼层</label>
                <div class="layui-input-inline">
                    <input type="number" name="higth" id="higth2" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">总层数</label>
                <div class="layui-input-inline">
                    <input type="number" name="allhigth" id="allhigth2" class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">经纪人</label>
                <div class="layui-input-inline">
                    <input type="text" name="aName" id="aName2" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-inline">
                    <input type="number" name="aphone" id="aphone2" class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">房东</label>
                <div class="layui-input-inline">
                    <input type="text" name="saName" id="saName2" class="layui-input" disabled>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">联系电话</label>
                <div class="layui-input-inline">
                    <input type="number" name="saphone" id="saphone2" class="layui-input" disabled>
                </div>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">详细描述</label>
            <div class="layui-input-block">
                <textarea name="details" id="details2" class="layui-textarea" disabled></textarea>
            </div>
        </div>
    </form>
</div>
<!-- 查看房屋的弹出层结束 -->

<script type="text/javascript" th:src="@{/layui/layui.js}"></script>
<script type="text/javascript">
    var tableIns;
    layui.extend({
        dtree: '../../layui_ext/dtree/dtree'   // {/}的意思即代表采用自有路径，即不跟随 base 路径
    }).use(['jquery', 'form', 'table', 'layer'], function () {
        var $ = layui.jquery;
        var form = layui.form;
        var table = layui.table;
        var layer = layui.layer;
        //加载 数据
        tableIns = table.render({
            elem: '#orderTable'
            , url: '/admin/order/allOrder'
            , toolbar: '#orderToolBar' //开启头部工具栏，并为其绑定左侧模板
            , title: '订单数据表'
            , page: true
            , cols: [ [
                {field: 'id', title: '订单号', align: 'center', width: '300'}
                , {field: 'cName', title: '城市', align: 'center', width: '140'}
                , {
                    field: 'type', title: '类型', align: 'center', width: '100', templet: function (d) {
                        if(d.type===1){
                            return '新房'
                        }else if(d.type===2){
                            return '二手房'
                        }else if(d.type===3){
                            return '租房'
                        }
                        return '<span style="color: red">出错</span>';
                    }
                }
                , {field: 'money', title: '成交金额', align: 'center', width: '160', templet: function (d) {
                        if(d.type===1 || d.type===2){
                            return d.money+"万元";
                        }
                        if(d.type===3){
                            return d.money+"元";
                        }
                    }}
                , {field: 'commission', title: '提成', align: 'center', width: '160'}
                , {field: 'time', title: '交易时间', align: 'center', width: '160'}
                , {field: 'oname', title: '买家', align: 'center', width: '120'}
                , {field: 'ophone', title: '买家手机号', align: 'center', width: '120'}
                , {field: 'aName', title: '经纪人', align: 'center', width: '120'}
                 , {field: 'aphone', title: '经纪人手机号', align: 'center', width: '120'}
                , {field: 'saName', title: '卖家/房东', align: 'center', width: '150'}
                 , {field: 'saphone', title: '卖家/房东手机号', align: 'center', width: '150'}
                ,  {
                    field: 'status', title: '状态', align: 'center', width: '90', templet: function (d) {
                        if(d.status===1){
                            return '<span style="color: blue">未付款</span>'
                        }else if(d.status===2){
                            return '<span style="color: green">已付款</span>'
                        }else if(d.status===3){
                            return '<span style="color: orange">已取消</span>'
                        }
                        return '<span style="color: red">出错</span>';
                    }
                }
                , {fixed: 'right', title: '操作', toolbar: '#orderRowBar', align: 'center', width: '200'}
            ] ]
            , done: function (res, curr, count) { //处理删除某一页最后一条数据的BUG
                if (res.data.length == 0 && curr != 1) {
                    tableIns.reload({
                        page: {
                            curr: (curr - 1)
                        }
                    });
                }
            }
        });

        $.ajax({
            url: "/admin/city/getCity1",
            success: function (res){
                var citys = res.data;
                var html = "<option value=''>请选择城市</option>";
                $.each(citys, function (index, item) {
                    html += "<option value='" + item.id + "'>" + item.name + "</option>";
                });
                $("#search_city").html(html);
                form.render("select");
            },
            dataType: "json"
        });

        //模糊查询
        form.on("submit(doSearch)", function (data) {
            tableIns.reload({
                where: data.field,
                page: {
                    curr: 1
                }
            });
            return false;
        });

        //监听行工具条的事件
        table.on("tool(orderTable)", function (obj) {
            var data = obj.data; //获得当前行数据
            switch (obj.event) {
                case 'delete':
                    deleteOrder(data);
                    break;
                case 'look1':
                    lookHouse1(data);
                    break;
                case 'look2':
                    lookHouse2(data);
                    break;
            }
            ;
        });

        //打开房屋的弹出层1
        function lookHouse1(data) {
            layer.open({
                type: 1,
                content: $("#lookDiv1"),
                area: ['800px', '600px'],
                title: '查看房屋',
                success: function () {
                    $("#dataFrm1")[0].reset();
                    var hId = data.hId;
                    //加载房屋信息到弹出层
                    $.ajax({
                        url: "/admin/house/look?id="+hId,
                        success: function (res){
                            form.val("dataFrm", res.data);
                        },
                        dataType: "json"
                    });
                }
            });
        }

        //打开房屋的弹出层2
        function lookHouse2(data) {
            layer.open({
                type: 1,
                content: $("#lookDiv2"),
                area: ['800px', '600px'],
                title: '查看房屋',
                success: function () {
                    $("#dataFrm2")[0].reset();
                    var hId = data.hId;
                    //加载房屋信息到弹出层
                    $.ajax({
                        url: "/admin/house/look?id="+hId,
                        success: function (res){
                            form.val("dataFrm", res.data);
                        },
                        dataType: "json"
                    });
                }
            });
        }

        //删除
        function deleteOrder(data) {
            layer.confirm('你确定要取消这个订单吗?', {icon: 3, title: '提示'}, function (index) {
                // alert(data.id);
                $.post("/admin/order/cancelOrder", {id: data.id}, function (res) {
                    if (res.code == 200) {
                        tableIns.reload();
                    }
                    layer.msg(res.msg);
                })
                layer.close(index);
            });
        }
    });
</script>

</body>
</html>